<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class public_controller extends MY_Controller
{
    public $view_data = array();

    public function __construct()
    {
        parent::__construct();
		$this->view_data['css'] = array();
		$this->view_data['js'] = array();
    }

    public function load_view($view_path_name)
    {
        
        $this->view_data['english_link'] = $this->get_english_link();
        $this->view_data['vietnam_link'] = $this->get_vietnam_link();
        $this->view_data['theme_path'] = base_url();
		$this->view_data['can_do_scroll_over_slideshow'] = $this->can_do_scroll_over_slideshow();
		$this->view_data['can_show_header'] = $this->can_show_header();
		$this->view_data['selected_menu_code'] = $this->get_selected_menu_code();
        $this->load->view('master_page/header',$this->view_data);
        $this->load->view($view_path_name,$this->view_data);
        $this->load->view('master_page/footer',$this->view_data);
    }

	/*
	 * Include css file in header. For example : $this->addCss('style').
	 */
	public function addCss($css_name)
	{
		$this->view_data['css'][] = $css_name;
	}

	/*
	 * Include javascript file to header. For example : $this->addJs('jquery').
	 */

	public function addJs($js_name)
	{
		$this->view_data['js'][] = $js_name;
	}


    public function get_english_link()
    {
        return '#';
    }

    public function get_vietnam_link()
    {
        return '#';
    }

	public function can_do_scroll_over_slideshow()
	{
		return TRUE;
	}

    public function can_show_header()
    {
        return FALSE;
    }

	public function get_selected_menu_code()
	{
		return '';
	}

    public function upload_image($input_file_name, $old_file_name = '', $upload_path = 'uploads/')
    {
        $upload_config['upload_path'] = $upload_path;
        $upload_config['allowed_types'] = '*';
        $upload_config['file_name'] = time();
        $this->upload->initialize($upload_config);

        if ($this->upload->do_upload($input_file_name)) {
            if ($old_file_name != '') $this->delete_file($old_file_name);
            $upload_data = $this->upload->data();
            $uploaded_file_name = $upload_path . $upload_data['file_name'];
        }
        else
        {
            $uploaded_file_name = $old_file_name;
        }

        return $uploaded_file_name;
    }


    public function upload_files($input_file_name, $old_file_name = '', $upload_path = 'uploads/attachment/')
    {
        $upload_config['upload_path'] = $upload_path;
        $upload_config['allowed_types'] = '*';
        $upload_config['file_name'] = time();
        $this->upload->initialize($upload_config);
        if ($this->upload->do_upload($input_file_name)) {
            if ($old_file_name != '') $this->delete_file($old_file_name);
            $upload_data = $this->upload->data();
            $uploaded_file_name = $upload_path . $upload_data['file_name'];
        }
        else
        {
            $uploaded_file_name = $old_file_name;

        }
        return $uploaded_file_name;
    }

    public function delete_file($file_path)
    {
        if (is_writeable($file_path) && is_file($file_path)) unlink($file_path);
    }

}